package com.juma.cartridge.toker;

import java.util.Date;

/**
 * 
 * @ClassName Token
 * @Description
 * @Author zhuangguangyou
 * @Date 2019年10月29日 下午5:57:57
 * @Version 1.0
 *
 */

public class Token {
    
    public static final String prefix = "toker.";
    private String name;
    private String id;
    private int timeoutInSec;
    /**
     * 到期时间
     */
    private Date expireTime;

    public Token(String name,String id,int timeoutInSec) {
        this.name = name;
        this.id = id;
        this.timeoutInSec = timeoutInSec;
        this.expireTime = new Date(System.currentTimeMillis()+(timeoutInSec*1000));
    }
    
    public String getId() {
        return id;
    }
    
    public String getName() {
        return name;
    }
    
    public int getTimeoutInSec() {
        return timeoutInSec;
    }

    public Date getExpireTime() {
        return expireTime;
    }
    
    public String getKey() {
        String key = prefix;
        if(name!=null && !name.trim().isEmpty()) {
            key = key.concat(name).concat(".");
        }
        key = key.concat(id);
        return key;
    }
    
}
